﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CSharpProjectLayers.BLL;
using CSharpProjectLayers.Models;

namespace CSharpProjectLayers.UI
{
    public class EmployeeUI
    {
        private EmployeeManager employeeManager = new EmployeeManager();
        /*        public void AddEmployee()
                {
                    Console.Write("请输入员工姓名：");
                    string EployName = Console.ReadLine();
                    Console.Write("请输入员工性别：");
                    string gender = Console.ReadLine();
                    Console.Write("请输入员工现在住址：");
                    string NowAddress = Console.ReadLine();
                    Console.Write("请输入员工身份证号码：");
                    string IdNo = Console.ReadLine();
                    Console.Write("请输入员工微信号码：");
                    string WeiXinNumber = Console.ReadLine();
                    Console.Write("请输入员工电话号码：");
                    string PhoneNumber = Console.ReadLine();
                    Console.Write("请输入员工其他工作：");
                    string OtherWork = Console.ReadLine();
                    Console.Write("请输入员工入职日期：");
                    string EntryDate = Console.ReadLine();
                    Console.Write("请输入员工职位编号：");
                    int PostId = int.Parse(Console.ReadLine());
                    Console.Write("请输入员工部门编号：");
                    int DepartmentId = int.Parse(Console.ReadLine());

                    //调用业务层方法
                    int result = employeeManager.AddEmployee(EployName, gender, NowAddress, IdNo, WeiXinNumber, PhoneNumber, OtherWork, Convert.ToDateTime(EntryDate), PostId, DepartmentId);
                    Console.WriteLine("添加员工，返回受影响的行数:" + result);
                }*/
        public void AddEmployeeByModels()
        {
            //创建实体对象
            Employee employee = new Employee();

            //封装实体属性
            Console.Write("请输入员工姓名：");
            employee.EployName = Console.ReadLine();
            Console.Write("请输入员工性别：");
            employee.Gender = Console.ReadLine();
            Console.Write("请输入员工现在住址：");
            employee.NowAddress = Console.ReadLine();
            Console.Write("请输入员工身份证号码：");
            employee.IdNo = Console.ReadLine();
            Console.Write("请输入员工微信号码：");
            employee.WeiXinNumber = Console.ReadLine();
            Console.Write("请输入员工电话号码：");
            employee.PhoneNumber = Console.ReadLine();
            Console.Write("请输入员工其他工作：");
            employee.OtherWork = Console.ReadLine();
            Console.Write("请输入员工入职日期：");
            employee.EntryDate = DateTime.Parse(Console.ReadLine());
            Console.Write("请输入员工职位编号：");
            employee.PostId = int.Parse(Console.ReadLine());
            Console.Write("请输入员工部门编号：");
            employee.DepartmentId = int.Parse(Console.ReadLine());

            //调用业务层方法
            int result = employeeManager.AddEmployee(employee);
            Console.WriteLine("添加员工，返回受影响的行数:" + result);
        }
        public void QueryEmployee()
        {
            Console.Write("请输入部门编号:");
            string departmentId = Console.ReadLine();
            List<Employee> eList = null;
            try
            {
                eList = employeeManager.QueryEmployeeByDepartmentId(departmentId);
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            if(eList != null && eList.Count != 0) //如果返回数据
            {
                foreach(Employee item in eList)
                {
                    Console.WriteLine($"{item.EployName}\t{item.Gender}\t{item.IdNo}\t{item.WeiXinNumber}\t{item.PhoneNumber}");
                }
            }
        }
    }
}
